<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--{include file='comm/header.tpl'}-->
    <title>生成插入更新SQL文件</title>
</head>
<body>

	<div style="width:100%">
		
		<!--{include file='comm/menu.tpl'}-->
		<div style="clear:both;"></div>
		<div style="float:left;width:300px;padding-left:30px;">
		
			<div>
				
				<h2 style="height:50px;font-size:14px;line-height:50px;">选择表：</h2>
				<span style="height:30px;line-height:30px;">
					查询：<input type="text" onkeyup="source.doScreen()"  id="screenName" name="screenName" style="width:130px;" />
				</span>
				
			</div>
			<!--{if $dataBase}-->
			<form id="searchForm">
					
				<select style="height:400px; width:170px; padding-left:7px;" multiple=true onchange="source.getInfo()" id="tableSelect" name="tableSelect">
					<!--{foreach from=$dataBase item=tb}-->
						<option ><!--{$tb->$tableName}--></option>
					<!--{/foreach}-->
				</select >
			</form>
			<!--{/if}-->
		
		</div>
		
		<div style="float:left;">
			
			<div>
				<h2 style="height:50px;font-size:14px;line-height:50px;padding-left:20px;">表明细：</h2>
			</div>
			<span id="dbName" name="dbName" style="padding-left:20px;"><!--{$dataBase.0->$tableName}--></span>
			<form id="tableForm" name="tableForm">
				<input type="hidden" id="tableName" name="tableName" value="<!--{$dataBase.0->$tableName}-->">
				<input type="hidden" id="operFlg" name="operFlg" value="">
			</form>
			<div id="flexTable" style="width:800px;height:440px;">
				<table id="flex" style="display:none"></table>
			</div>
						
		</div>
		<div style="clear:both;"></div>
		<!--{include file='comm/footer.tpl'}-->
		
	</div>


<script>
	$("#flex").flexigrid({
			url:"/invokingAjax-backend/project/sqlinc.ajax?operFlg=1",
	        dataType: "json",
	        colModel : [
				{display: "Field", width : 150 },
	            {display: "Type", width : 150},
	            {display: "Key", width : 80},
	            {display: "Comment", width : 400}
	        ],
			buttons: [
				{name: "生成insert", bclass: "export", onpress : "source.insert"},
				{separator: true},
				{name: "生成update", bclass: "export", onpress : "source.update"}
			],

	        showTableToggleBtn: true,
			width: 780,
			height:350
		});
		
		var source = {
			doScreen: function(){
				var screenName = $('#screenName').val();
				$.ajax({
					type: "POST",
					url:  "/invokingAjax-backend/project/sqlinc.ajax?operFlg=2",
					data: {'screenName' : screenName},
					dataType: "JSON",
					success: function( result_obj ) {
	                    $('#tableSelect').html(result_obj);
	                }
				});
			},
			
			insert: function(){
				$('#operFlg').val('2');
				var tableForm = document.getElementById('tableForm');
				tableForm.action = '/quanliadmin/app/project/sqlinc.pscript?operFlg=1';
				tableForm.submit();
				
			},
			
			update: function(){
				$('#operFlg').val('3');
				var tableForm = document.getElementById('tableForm');
				tableForm.action = '/quanliadmin/app/project/sqlinc.pscript?operFlg=1';
				tableForm.submit();
			},
			
			getInfo: function(){
				var dbName = $('#tableSelect').find("option:selected").text();
				$('#dbName').html(dbName);
				$('#tableName').val(dbName);
				var dt = $('#searchForm').serializeArray();
	            $("#flex").flexOptions({params: dt}).flexReload();
				
			},
			
			load: function() {
	            $("#flex").flexReload();
	        },
		};
		
		
</script>
</body>
</html>